home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 090 / timings.arc / TIMERS01.ASM < prev    next >
Encoding:
Assembly Source File  |  1986-01-18  |  2.3 KB  |  89 lines

  1.     title    TIMERS01 -- High Resolution Timer Setup
  2.     page    60,120
  3.  
  4.     name    TIMERS01    ; module
  5.  
  6. comment |         Module Specifications
  7.  
  8. Copyright: None.
  9.  
  10. Environment: IBM PC, tested under DOS 2.0.
  11.  
  12. Segmentation: Program segment CODE, public, byte aligned, class ''.
  13.  
  14. Public symbols and external references: See Symbols section of listing.
  15.  
  16. Link requirements: None, standalone subroutine.
  17.  
  18. Program derived from: None.
  19.  
  20. Original code by: Bob Smith and Tom Puckett, October 1983.
  21.  
  22. Modifications by: None.
  23.  
  24.  
  25.             Procedure Specifications
  26.  
  27. Public Procedure TIMERS01 -- High Resolution Timer Setup
  28.  
  29.     This is a subroutine to set up Counter 0 of the 8253 to run in Mode 2.
  30.     It normally runs in Mode 3, which makes its residual count values
  31.     useless for high resolution timing purposes since in this mode it counts
  32.     down by twos, with two countdowns per cycle.  In Mode 2 there is a
  33.     single countdown per cycle, by ones, so the residual count values are
  34.     meaningful.  (See routine TIMERR02 for recovering timing information.)
  35.  
  36.     Assumptions: Counter 0 is to be set to normal count of 65536.
  37.  
  38.     Linkage: Near call and return.
  39.  
  40.     Arguments: None.
  41.  
  42.     Effects: Counter 0 set to mode 2, count 65536, binary.
  43.  
  44.     Results: Flags destroyed.
  45.  
  46.     Return conditions: None.
  47.  
  48.     Limitations: None.
  49.  
  50. |
  51.     page
  52.  
  53. code    segment    public byte
  54.     assume    cs:code
  55.  
  56. ; equates....
  57.  
  58. timer_0    equ    40h        ; 8253 counter 0 port
  59. timer_ctl equ    43h        ; 8253 control port
  60. timer_set equ    00110100b    ; 8253 Counter 0, set LOB/HOB, mode 2, binary
  61.  
  62.     public    TIMERS01
  63. TIMERS01 proc    near        ; see specifications at head of listing
  64.  
  65.     push    ax        ; preserve
  66.     push    cx
  67.  
  68.     mov    al,timer_set
  69.     out    timer_ctl,al    ; set Counter 0 parameters, prime load trigger
  70.     xor    al,al        ; zero will give full count of 65536
  71.     nop            ; insure 5 clocks for 8253 recovery time
  72.     out    timer_0,al    ; load low order byte
  73.     nop            ; 8253 recovery time
  74.     nop            ;  "       "      "
  75.     out    timer_0,al    ; load high order byte
  76.  
  77.     mov    cx,20000    ; must be sure previous countdown has completed,
  78. loop:    loop    loop        ; so spin here 70 milliseconds to guarantee it
  79.  
  80.     pop    cx        ; restore
  81.     pop    ax
  82.     ret
  83.  
  84. TIMERS01 endp
  85.  
  86. code    ends            ; end code segment
  87.  
  88.      end            ; end module
  89.